package com.yyx.app1.My_function.UI;

import android.app.Activity;
import android.content.Context;
import android.graphics.Point;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yyx.app1.CommonControls.MyViewPager.BackButton;
import com.yyx.app1.CommonControls.MyViewPager.MyViewPager;
import com.yyx.app1.My_function.Controls.ViewPager.ListView_ViewPagerOfChild;
import com.yyx.app1.My_function.Controls.ViewPager.ListView_ViewPagerOfChild_;
import com.yyx.app1.My_function.Controls.ViewPager.MyViewPagerAdapter;
import com.yyx.app1.R;
import com.yyx.app1.tool.ImageTool;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.res.ColorRes;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/10/24.
 */
@EActivity(R.layout.activity_hospitalappointment)
public class HospitalAppointment_Activity extends Activity {
    @ViewById
    BackButton all,runtime,notbeginning;

    @ViewById
    MyViewPager viewpager;

    @ViewById
    LinearLayout Slider;

    @ColorRes
    int gray_unselcet_font,app_color;

    @AfterViews
    public void init()
    {
        try
        {
            BackButton[]  backButtons = new BackButton[]{all,runtime,notbeginning};
            int[] selectImages = new int[]{R.drawable.ico_book2,R.drawable.ico_document2,R.drawable.agenda2};
            int[] unSelectImages = new int[]{R.drawable.ico_book,R.drawable.ico_document,R.drawable.agenda};
            String[] names = new String[]{"全 部","预 约","结 束"};
            for (int i= 0 ; i<backButtons.length;++i)
            {
                if (i==0)
                {
                    backButtons[i].getText().setText(names[i]);
                    backButtons[i].getText().setTextColor(app_color);
                    backButtons[i].getImage().setImageResource(selectImages[i]);
                }
                else
                {
                    backButtons[i].getText().setText(names[i]);
                    backButtons[i].getText().setTextColor(gray_unselcet_font);
                    backButtons[i].getImage().setImageResource(unSelectImages[i]);
                }
                backButtons[i].SetStyle();
            }
            //填充ViewPager的ChildView------------------------
            List<View> views = new ArrayList<>();
            String[] strs = new String[]{"appointment_all","appointment_unstart","appointment_over"};
            for (int i=0 ; i<3; ++i)
            {
                ListView_ViewPagerOfChild listview = ListView_ViewPagerOfChild_.build(this);
                listview.init(strs[i]);
                views.add(listview);
            }
            Point size = ImageTool.getScreenSize(this);
            viewpager.setAdapter(new MyViewPagerAdapter(this, views));
            ImageView image = new ImageView(this);
            image.setLayoutParams(new LinearLayout.LayoutParams(size.x/views.size(), ViewGroup.LayoutParams.MATCH_PARENT));
            image.setImageResource(R.drawable.yuanjiao_ico_appcolor);
            image.setPadding(ImageTool.dip2px(this,20),0,ImageTool.dip2px(this,20),0);
            Slider.removeAllViews();
            Slider.addView(image);
            viewpager.init(views.size(), size.x, Slider, backButtons, gray_unselcet_font, app_color, selectImages, unSelectImages);
        }
        catch (Exception e)
        {
            Log.e("异常1510241800", e.toString());
        }
    }

    @Click
    public void home()
    {
        finish();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            home();
        }
        return true;
    }
}
